#include "parser.h"

Token File::peek(int offset) {
    return (token_group[this->segment + offset]);
}

DefineStatementNode* File::isDefineStatementNode() {
    bool first = peek(0).first == Identifier and this->parent->classes.count(peek(0).second);
    bool second = peek(1).first == Identifier;

    if (first and second) {
        DefineStatementNode* node = new DefineStatementNode();
        node->type = peek(0).second;
        node->name = peek(1).second;
        this->segment += 2;
        bool third = peek(0).first == Symbol and peek(1).second == "=";
        bool forth = false;
        if (third and forth) {

        }
        return node;
    } else {
        return nullptr;
    }
}

File::File(const std::string &file_name) {
    this->file_name = file_name;
    this->token_group = lexer(file_reader(file_name));
    this->parent->classes = {{"var", nullptr}};

    this->segment = 0;
    while (segment <= token_group.size()) {
        DefineStatementNode* defineStatementNode = isDefineStatementNode();
        if (defineStatementNode != nullptr)
            this->parent->statements.push_back(defineStatementNode);
        segment++;
    }
    std::cout << this->parent->statements.size();
}

Parser::Parser(std::string file_name) {
    this->files[file_name] = new File(file_name);
}